package com.project.controller;

import com.project.bean.FacilitiesBean;
import com.project.service.IFacilitiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("facilities")
public class FacilitiesController {
    @Autowired
    private IFacilitiesService service;

    /**
     * 按房间id查询设施集合
     * @param roomId 房间id
     * @return 设施集合
     */
    @RequestMapping("findByRoomId")
    public List<FacilitiesBean> findByRoomId(Integer roomId){
        return service.findByRoomId(roomId);
    }

    /**
     * 按id修改设施状态
     * 将指定设设施状态，修改为已解决，同时统计房间里未解决设施的数量，如果为0，则将房间的状态修改为正常。
     * @param id 设施id
     * @param roomId 房间id
     */
    @RequestMapping("updateState")
    public String updateState(Integer id,Integer roomId){
        service.updateState(id,roomId);
        return "ok";
    }

    /**
     * 添加
     * @param state 设施状态
     * @param roomId 房间id
     * @return
     */
    @RequestMapping("add")
    public String add( String state ,Integer roomId ){
        FacilitiesBean facilities = new FacilitiesBean(state,roomId);
        service.add(facilities);
        return "ok";
    }
}
